Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Language Guide / Part 2 - AppleScript Language Reference
Chapter 7 - Control Statements


Characteristics of Control Statements

Most control statements are compound statements that contain other statements. For example, the If statement

if today = last day of theMonth
   set MonthlyReport to prepareReport(currentMonth)
   print MonthlyReport
end if
is a compound statement that contains a Set command and a Print command. Compound statements begin with one or more reserved words, such as if in the example above, that identify the type of compound statement. The last line of a compound statement is always end, which can optionally include the word that begins the control statement.

Control statements can contain other control statements. For example, this Tell statement contains the If statement of the previous example.

tell application "ReportWizard"   if today = last day of theMonth
      set MonthlyReport to prepareReport(currentMonth)
      print MonthlyReport
   end if
end tell
Control statements that are contained within other control statements are sometimes called nested control statements.

All control statements can be compound statements. In addition, some control statements can be written as single statements. For example, the statement

if (x > y) then return x
is equivalent to

if (x > y) then
   return x
end if
You can use a simple statement only when you're controlling the execution of a single statement (such as return x in the previous example).


Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996